package ru.ifmo.sound.jmlbased;

import net.sf.javaml.core.Dataset;
import net.sf.javaml.core.Instance;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author avhaliullin
 */
public class WrapperMethods {

    public static double[] instanceToArray(Instance instance) {
        double[] res = new double[instance.values().size()];
        int i = 0;
        for (Double val : instance) {
            res[i++] = val;
        }
        return res;
    }


    public static Map<String, List<double[]>> mapByDataset(Dataset dataset) {
        Map<String, List<double[]>> res = new HashMap<String, List<double[]>>();
        for (Instance instance : dataset) {
            List<double[]> list = res.get(String.valueOf(instance.classValue()));
            if (list == null) {
                list = new ArrayList<double[]>();
                res.put(instance.classValue().toString(), list);
            }
            list.add(instanceToArray(instance));
        }
        return res;
    }

}
